package servlet;


import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.InvoiceDAO;
import net.sf.json.JSONObject;
/**
 * Servlet implementation class GetData
 */
@WebServlet("/GetDatadata")
public class GetDatadata extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4526773232200538L;

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		this.doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.setContentType("text/json; charset=utf-8");
        JSONObject jsonObj=new JSONObject();
        InvoiceDAO dao=new InvoiceDAO();
        Map<String, Integer> map = new HashMap<String, Integer>();
         List<Integer> clist1;
		try {
			clist1 = dao.acquire();
		     map.put("sone",clist1.get(0));
	         map.put("stwo",clist1.get(1));
	         map.put("sthree",clist1.get(2));
	         map.put("sfour",clist1.get(3));
	         map.put("fone",clist1.get(4));
	         map.put("ftwo",clist1.get(5));
	         map.put("fthree",clist1.get(6));
	         map.put("ffour",clist1.get(7));
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
         jsonObj.putAll(map);
         response.getWriter().println(jsonObj.toString()); 
	}



}
